package fr.umlv.m2.jee.spij.persistence.schooling.dao;

import fr.umlv.m2.jee.spij.framework.dao.hibernate.AbstractHibernateDAO;
import fr.umlv.m2.jee.spij.persistence.schooling.Course;
import fr.umlv.m2.jee.spij.persistence.schooling.ICourseDAO;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("hibernateCourseDAO")
public class HibernateCourseDAO extends AbstractHibernateDAO<Long, Course>
        implements ICourseDAO {

    @Override
    public Course findByName(String name) {
        Session session = getHibernateSession();
        Criteria criteria = session.createCriteria(Course.class);
        criteria.add(Restrictions.like("name", name));
        return (Course) criteria.uniqueResult();
    }
}
